package com.limao.Admin.Servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.limao.Model.LzPluginException;
import com.limao.Tool.CacheClass;
import com.limao.Tool.Function;

@WebServlet(name="Reg", urlPatterns="/Reg",asyncSupported=false)
public class RegServlet extends HttpServlet {

	private static final long serialVersionUID = 2335165719284386850L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub 
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		String errMessage = "";
		HttpSession session = request.getSession(); 
		
		/*首先取得命令参数信息*/
		String mStr = request.getParameter("m");
		int m=CacheClass.getIntValue(mStr);
		try {
			switch(m)
			{
			case Function.REG_OPERATION_WEB:
				adminLoinInfo.reg_web(session, request,response);
				break;
			case Function.REG_OPERATION:
				adminLoinInfo.myqrcode(session, request,response);
				break;
			default:
				errMessage += "无此功能号!";
				request.setAttribute("errMessage",errMessage);
				RequestDispatcher wm = request.getRequestDispatcher("login.jsp");
				wm.forward(request, response);
				
			}
		} catch (LzPluginException e) {
			errMessage += e.getMessage();
			request.setAttribute("errMessage",errMessage);
			RequestDispatcher wm = request.getRequestDispatcher("login.jsp");
			wm.forward(request, response);
		}
	}
}
